import { createRouter, createWebHashHistory } from 'vue-router'

const routes = [
  {
    path: '/',
    component: () => import('@/views/Layout'),
    children: [
      {
        // 空字符串表示默认路由，一进Layout就默认展示Home页
        path: '',
        component: () => import('@/views/Home')
      },
      {
        // 一级分类
        path: 'category/:id',// 动态路由
        component: () => import('@/views/Category')
      },
      {
        // 二级类目
        path: '/category/sub/:id',
        component: () => import('@/views/Category/Sub')
      },
      {
        // 商品详情
        path: '/goods/:id',
        component: () => import('@/views/Goods')
      }
    ]
  },
  {
    path: '/text',
    component: () => import('@/views/Playground')
  }
]

const router = createRouter({
  // 使用hash方式实现路由
  history: createWebHashHistory(),
  // 配置路由规则，写法和之前一样
  routes,
  // 刷新行为时，回到顶部
  // scrollBehavior: () => ({ x: 0, y: 0 })// vue2的写法
  scrollBehavior: () => ({ top: 0 }) // vue3的写法
})

export default router
